<template>
	<view class="container">
		<view class="form-card">
			<text class="form-title">登录</text>

			<input class="input-field" placeholder="请输入用户名" v-model="username" />

			<input class="input-field" placeholder="请输入密码" password
				v-model="password" :focus="isPwdfocus" @blur="isPwdfocus = false" />

			<button class="action-btn" type="primary" @click="handleLogin">登录</button>

			<view class="link-area">
				<text>没有账号？</text>
				<navigator url="/pages/register/register">去注册</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: 'ld',
				password: '123456',
				isPwdfocus: true
			};
		},
		methods: {
			handleLogin() {
				if (!this.username || !this.password) {
					uni.showToast({
						title: '请输入完整信息',
						icon: 'none'
					});
					return;
				}
				console.log("handleLogin()-->登录验证 " + this.username);
				if (this.username === 'ld' && this.password === '123456') {
					uni.showLoading({
						title: '登录中...'
					});
					console.log("handleLogin()-->登录验证成功");
					
					setTimeout(() => {
						uni.hideLoading();
						uni.showToast({
							title: '登录成功'
						});
						uni.setStorage({
						  key: 'Account', // 自由命名
						  data: this.username,
						  success() {
						    console.log("Account存储成功");
						  },
						  fail(e) {
						    console.log("Account存储失败:" + e);
						  },
						  complete() {
						    console.log("Account存储完成");
						  }
						});
						uni.switchTab({
							url: "/pages/NewsTaBar/newsPage/newsPage"
						});
					}, 1000);
				} else {
					console.log("handleLogin()-->登录验证失败");
					uni.showToast({
						title: '密码错误, 请重新输入',
						icon: 'none'
					});
					this.password = '';
					this.isPwdfocus = true;
				}
			}
		}
	}
</script>

<style scoped>
	.container {
		display: flex;
		justify-content: center;
		align-items: center;
		min-height: 100vh;
		background-color: #f5f7fa;
	}


	.form-card {
		width: 80%;
		max-width: 400px;
		background-color: #fff;
		padding: 40rpx;
		border-radius: 12rpx;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.form-title {
		font-size: 36rpx;
		font-weight: bold;
		margin-bottom: 30rpx;
		color: #333;
	}

	.input-field {
		width: 100%;
		height: 80rpx;
		border: 2rpx solid #e5e5e5;
		border-radius: 8rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
		font-size: 28rpx;
		margin-bottom: 20rpx;
	}

	.action-btn {
		width: 100%;
		height: 80rpx;
		border-radius: 8rpx;
		font-size: 30rpx;
	}

	.link-area {
		margin-top: 20rpx;
		font-size: 26rpx;
		color: #666;
	}

	.link-area navigator {
		color: #007AFF;
		text-decoration: none;
	}
</style>